package com.nanrui.mutualinductor;

import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

import com.nanrui.mutualinductor.communicate.PacketCallback;
import com.nanrui.mutualinductor.data.DKPacket;

public class AidlPacket<T extends DKPacket>
        implements Parcelable {
    public static final Parcelable.Creator<AidlPacket> CREATOR = new Parcelable.Creator() {
        @Override
        public AidlPacket createFromParcel(Parcel paramAnonymousParcel) {
            return new AidlPacket(paramAnonymousParcel);
        }

        @Override
        public AidlPacket[] newArray(int paramAnonymousInt) {
            return new AidlPacket[paramAnonymousInt];
        }
    };
    public static final String KEY_DK_PACKET = "DKPacket";
    public static final String KEY_PACKET_CALLBACK = "Callback";
    private PacketCallback<T> callback;
    private DKPacket dkPacket;

    protected AidlPacket(Parcel paramParcel) {
        this.dkPacket = ((DKPacket) paramParcel.readBundle(getClass().getClassLoader()).getSerializable("DKPacket"));
        this.callback = ((PacketCallback) paramParcel.readBundle(getClass().getClassLoader()).getBinder("Callback"));
    }

    public AidlPacket(T paramT, PacketCallback<T> paramPacketCallback) {
        this.dkPacket = paramT;
        this.callback = paramPacketCallback;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public PacketCallback<T> getCallback() {
        return this.callback;
    }

    public DKPacket getDkPacket() {
        return this.dkPacket;
    }

    @Override
    public void writeToParcel(Parcel paramParcel, int paramInt) {
        Bundle localBundle = new Bundle();
        localBundle.putSerializable("DKPacket", this.dkPacket);
        localBundle.putBinder("Callback", this.callback);
        paramParcel.writeBundle(localBundle);
    }
}

